# Contributor: Carlo Bramini <carlo_bramini@users.sourceforge.net>

_realname=mxml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.1
pkgrel=2
pkgdesc="A tiny XML library for reading and writing XML files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://www.msweet.org/mxml/"
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/michaelrsweet/${_realname}/archive/v${pkgver}.tar.gz"
         0001-autoconf-remove-options-for-clang.patch
         0002-makefile-install-dll.patch)
sha256sums=('59eba16ce43765f2e2a6cf4873a58d317be801f1e929647d85da9f171e41e9ac'
            'a05cd5621a1c5bc5f0977adf7e0282319c6c2408346913a6f5fe1b7e180eb5f9'
            '95f8947746e9ee5e7e7fb0b453bc0953e825c1ccf7559936f49b870a95f8c7f6')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i ${srcdir}/0001-autoconf-remove-options-for-clang.patch
  patch -p1 -i ${srcdir}/0002-makefile-install-dll.patch
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"
  cp -a "../${_realname}-${pkgver}/." .

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make DSTROOT="${pkgdir}" install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
